import { Component } from "vue"

// 登录信息收集
export interface LoginForm {
    account: string
    password: string
}

export enum Gender {
    MALE=1,
    FEMALE=2,
}

// 新用户注册信息
export interface RegisterForm {
    account: string,
    password: string,
    confirmPassword: string,
    realName: string,
    gender: Gender,
    department: string,
    employeeId: string,
    phoneNo: string,
    email: string,
    registerPublic: number,  // 是否同时注册公共账号
    publicAccount: string,
    publicPassword: string,
    confirmPublicPassword: string,
}

// 侧边导航菜单路由信息
export interface MenuRouteInfo {
    name: string,
    path: string,
    redirect?: string
    component?: () => Component
    meta: {
        title?: string,
        icon?: string,
        showInAsideMenu: boolean,
    },
    children?: Array<MenuRouteInfo>
}


// 用户申请容量信息
export interface ApplyInfo {
    account: string,
    applyType: number,
    applyVolume: number,
    applyReason: string,
}


export type UploadFiles = UploadFile[]
export type UploadStatus = 'ready' | 'uploading' | 'success' | 'fail'
export interface UploadFile {
  name: string
  percentage?: number
  status: UploadStatus
  size?: number
  response?: unknown
  uid: number
  url?: string
  raw?: UploadRawFile
}
export interface UploadRawFile extends File {
  uid: number
}

interface UploadProgressEvent extends ProgressEvent {
    percent: number
}

class UploadAjaxError extends Error {
    name = 'UploadAjaxError'
    status: number
    method: string
    url: string
  
    constructor(message: string, status: number, method: string, url: string) {
      super(message)
      this.status = status
      this.method = method
      this.url = url
    }
}

export interface UploadRequestOptions {
    action: string
    method: string
    data: Record<string, string | Blob | [string | Blob, string]>
    filename: string
    file: File
    headers: Headers | Record<string, string | number | null | undefined>
    onError: (evt: UploadAjaxError) => void
    onProgress: (evt: UploadProgressEvent) => void
    onSuccess: (response: any) => void
    withCredentials: boolean
  }